function set(name, value, expire = 30) {
    let now = new Date(new Date().getTime() + expire * 60 * 1000)
    document.cookie = `${name}=${value};expires=${now.toUTCString()}`;
}

function remove(name, value = '') {
    let now = new Date(0)
    document.cookie = `${name}=${value};expires=${now.toUTCString()}`;
}

function exists(name) {
    let flag = false;
    let cs = document.cookie.split("; ");
    for (c of cs) {
        if (c.startsWith(name + "=")) {
            flag = true;
            break;
        }
    }
    return flag;
}

function get(name) {
    let cs = document.cookie.split("; ");
    let vv = cs.join(",");
    for (c of cs) {
        if (c.startsWith(name + "=")) {
            vv = c.substr(c.lastIndexOf("=") + 1);
            break;
        }
    }
    return vv;
}

